package com.work.servlet;

import com.work.dao.GoodsDao;
import com.work.dao.GoodsDaoImpl;
import com.work.pojo.Goods;
import com.work.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName: QueryServlet
 * @Description: TODO
 * @author: meyolo
 * @date: 2021/3/19  18:30
 * 主页查询显示Servlet
 */
@WebServlet(name = "QueryServlet", urlPatterns = "/query")
public class QueryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsDao goodsDao = new GoodsDaoImpl();
        //调取商品信息
        List<Goods> goodsList = goodsDao.queryAllGoods();
        request.setAttribute("goodsList", goodsList);
        //获得当前用户存储在Session中的信息，传给主页
        User user = (User) request.getSession().getAttribute("user");
        request.setAttribute("user", user);

        request.getRequestDispatcher("/index.jsp").forward(request, response);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
